home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
VideoFolder 1.0a
/
Source
/
SequenceGrabberPane.cp
< prev
next >
Wrap
Text File
|
1996-06-21
|
5KB
|
233 lines
#include <Errors.h>
#include "MoreFilesExtras.h"
#include "SequenceGrabberPane.h"
SequenceGrabberPane* SequenceGrabberPane::CreateSequenceGrabberPaneStream(LStream *inStream)
{
return new SequenceGrabberPane ( inStream );
}
SequenceGrabberPane::SequenceGrabberPane()
{
}
SequenceGrabberPane::SequenceGrabberPane(const SequenceGrabberPane &inOriginal)
{
}
// SequenceGrabberPane::SequenceGrabberPane(const SSequenceGrabberPaneInfo &inSequenceGrabberPaneInfo);
SequenceGrabberPane::SequenceGrabberPane(LStream *inStream) :
LView ( inStream )
{
}
SequenceGrabberPane::~SequenceGrabberPane()
{
StopIdling();
if (fSequenceGrabberComponent)
{
SGStop (fSequenceGrabberComponent);
CloseComponent (fSequenceGrabberComponent);
}
if ( mGWorld )
delete mGWorld;
if (fQuickTime)
ExitMovies ();
}
void SequenceGrabberPane::SetUpdateDirectToScreen ( )
{
#if 0
if ( GetMacPort() )
{
ThrowIfOSErr_( ::SGSetUseScreenBuffer ( fVideoChannel, true ) );
ThrowIfOSErr_( ::SGSetGWorld ( fVideoChannel, (GWorldPtr) GetMacPort(), nil ) );
Rect frameRect;
if ( CalcPortFrameRect ( frameRect ) )
ThrowIfOSErr_( ::SGSetChannelBounds ( fVideoChannel, & frameRect ) );
}
#endif
}
void SequenceGrabberPane::DoSetupDialog ( )
{
OSErr err = SGSettingsDialog ( fSequenceGrabberComponent, fVideoChannel, 0, nil, 0, nil, 0 );
if ( err == userCanceledErr )
err = noErr;
ThrowIfOSErr_( err );
}
void SequenceGrabberPane::DrawSelf ( )
{
Rect frameRect;
if (fSequenceGrabber && CalcPortFrameRect ( frameRect ) )
{ GrafPtr currentPort;
GetPort ( & currentPort );
// Rect gWorldRect = mGWorld->GetMacGWorld()->portRect;
mGWorld->CopyImage ( currentPort, frameRect );
// SGUpdate ( fSequenceGrabberComponent, GetMacPort()->visRgn );
}
}
void SequenceGrabberPane::FinishCreate()
{
fSequenceGrabber = false;
fSequenceGrabberComponent = nil;
mGWorld = nil;
// Initialize QuickTime.
long gestaltResponse;
if (Gestalt (gestaltQuickTime, &gestaltResponse) == noErr && EnterMovies () == noErr)
fQuickTime = true;
else
fQuickTime = false;
InitializeSequenceGrabber ();
StartIdling();
// SetUpdateDirectToScreen();
}
void SequenceGrabberPane::Grab ( )
{ Byte wasPaused = seqGrabPause;
ThrowIfOSErr_( SGGetPause ( fSequenceGrabberComponent, & wasPaused ) );
if ( seqGrabPause != seqGrabUnpause )
{
SGPause ( fSequenceGrabberComponent, seqGrabUnpause );
Refresh();
}
SGIdle ( fSequenceGrabberComponent );
ThrowIfOSErr_( SGPause ( fSequenceGrabberComponent, wasPaused ) );
}
void SequenceGrabberPane::InitializeSequenceGrabber ( )
{ OSErr error = noErr;
const unsigned kPixelDepth = 0;
Try_ {
ThrowIfNot_( fQuickTime );
// Initialize the sequence grabber component.
fSequenceGrabberComponent = ::OpenDefaultComponent (SeqGrabComponentType, 0);
ThrowIfNil_( fSequenceGrabberComponent );
ThrowIfOSErr_ ( ::SGInitialize (fSequenceGrabberComponent) );
// Initialize a video channel.
ThrowIfOSErr_( ::SGNewChannel (fSequenceGrabberComponent, VideoMediaType, &fVideoChannel) );
Rect frameRect = { 0, 0, 240, 320 };
CalcPortFrameRect ( frameRect );
mGWorld = new LGWorld ( frameRect, 0, useTempMem );
ThrowIfOSErr_( ::SGSetGWorld (fSequenceGrabberComponent, mGWorld->GetMacGWorld(), nil) );
// ThrowIfOSErr_( ::SGGetSrcVideoBounds (fVideoChannel, & mSourceVideoBounds) );
ThrowIfOSErr_( ::SGSetChannelBounds ( fVideoChannel, & frameRect ) );
ThrowIfOSErr_( ::SGSetChannelUsage (fVideoChannel, seqGrabPreview | seqGrabPlayDuringRecord) );
SGSetUseScreenBuffer ( fVideoChannel, false );
// SetUpdateDirectToScreen();
// Start video capture.
ThrowIfOSErr_( ::SGStartPreview (fSequenceGrabberComponent) );
fSequenceGrabber = true;
}
Catch_ ( inErr )
{
if (fSequenceGrabberComponent) {
CloseComponent (fSequenceGrabberComponent);
fSequenceGrabberComponent = nil;
}
if ( mGWorld ) {
delete mGWorld;
mGWorld = nil;
}
fSequenceGrabber = false;
Throw_( inErr );
}
}
void SequenceGrabberPane::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
{
LPane::ResizeFrameBy ( inWidthDelta, inHeightDelta, false );
Rect frameRect;
if ( CalcPortFrameRect ( frameRect ) )
{
ThrowIfOSErr_( ::SGStop (fSequenceGrabberComponent) );
delete mGWorld;
mGWorld = new LGWorld ( frameRect, 0, useTempMem );
ThrowIfOSErr_( ::SGSetGWorld (fSequenceGrabberComponent, mGWorld->GetMacGWorld(), nil) );
ThrowIfOSErr_( ::SGSetChannelBounds ( fVideoChannel, & frameRect ) );
ThrowIfOSErr_( ::SGStartPreview (fSequenceGrabberComponent) );
Grab();
}
if ( inRefresh )
Refresh();
}
void SequenceGrabberPane::SetLiveUpdate ( Boolean newValue )
{
if ( newValue )
{
SGPause ( fSequenceGrabberComponent, seqGrabUnpause );
StartIdling ();
}
else
{
SGPause ( fSequenceGrabberComponent, seqGrabPause );
StopIdling();
}
mLiveUpdate = newValue;
}
void SequenceGrabberPane::SpendTime( const EventRecord &inMacEvent)
{
if ( fSequenceGrabberComponent )
SGIdle ( fSequenceGrabberComponent );
Boolean drawingOnscreen;
ThrowIfOSErr_( ::SGGetUseScreenBuffer ( fVideoChannel, & drawingOnscreen ) );
if ( mLiveUpdate && ! drawingOnscreen && FocusDraw() )
DrawSelf ();
}
Handle SequenceGrabberPane::GetConfiguration () const
{
return NewHandle ( 0 );
}
void SequenceGrabberPane::SetConfiguration ( Handle h )
{
}